import { execute } from "../../database/connector";

import { ProjectDeclareQueries } from "../queries/project-declare.query";
import { IProjectDeclare } from "../../models/project-declare.model";

/**
 * gets active ProjectDeclare
 */
export const getProjectDeclares = async () => {
  return execute<IProjectDeclare[]>(ProjectDeclareQueries.GetProjectDeclares, []);
};

/**
 * gets a ProjectDeclare based on id provided
 */
export const getProjectDeclareById = async (id: IProjectDeclare['id']) => {
  return execute<IProjectDeclare>(ProjectDeclareQueries.GetProjectDeclareById, [id]);
};

/**
 * adds a new active ProjectDeclare record
 */
export const insertProjectDeclare = async (ProjectDeclare: IProjectDeclare) => {
    console.log('ProjectDeclare',ProjectDeclare)
  const result = await execute<{ affectedRows: number }>(ProjectDeclareQueries.AddProjectDeclare, [
    [Object.values(ProjectDeclare)]
  ]);
  return result.affectedRows > 0;
};

/**
 * updates ProjectDeclare information based on the id provided
 */
export const updateProjectDeclare = async (ProjectDeclare: IProjectDeclare) => {
  const result = await execute<{ affectedRows: number }>(ProjectDeclareQueries.UpdateProjectDeclareById, [
    ProjectDeclare,
    ProjectDeclare.id
  ]);
  return result.affectedRows > 0;
};

/**
 * updates ProjectDeclare information based on the id provided
 */
 export const deleteProjectDeclare = async (id: IProjectDeclare['id']) => {
  const result = await execute<{ affectedRows: number }>(ProjectDeclareQueries.DeleteProjectDeclareById, [
    id
  ]);
  return result.affectedRows > 0;
};